/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Reportes;
import java.sql.ResultSet;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;

/**
 *
 * @author usuario
 */
public class xCajaXCongreso extends ManejaExcel {

    public xCajaXCongreso(String name, String param1, String param2,int opc1, String opc2){
        super(name,param1,param2,opc1,opc2);
        
    }

    
    protected void escribirInfo() {

       try{ 

        WritableSheet s1 = workbook.createSheet("Clientes", 0);
        s1.setColumnView(1,25);
        s1.setColumnView(2,25);
        s1.setColumnView(3,30);
        
       
        //Carga primer fila con los titulos
        Label l1 = new Label(1,0,"Congreso", arial10BoldFormat);
        s1.addCell(l1);
        Label l2 = new Label(2,0,"Fecha Congreso", arial10BoldFormat);
        s1.addCell(l2);
        Label l3 = new Label(3,0,"Saldo Inicial", arial10BoldFormat);
        s1.addCell(l3);
         Label l4 = new Label(4,0,"DVDs vendidos", arial10BoldFormat);
        s1.addCell(l4);
         Label l5 = new Label(5,0,"Cant Pedidos", arial10BoldFormat);
        s1.addCell(l5);
         Label l6 = new Label(6,0,"Ventas en AR$", arial10BoldFormat);
        s1.addCell(l6);
         Label l7 = new Label(7,0,"Ventas M2", arial10BoldFormat);
        s1.addCell(l7);
         Label l8 = new Label(8,0,"Ventas M3", arial10BoldFormat);
        s1.addCell(l8);
        Label l9 = new Label(9,0,"Ventas Pendientes", arial10BoldFormat);
        s1.addCell(l9);
        Label l10 = new Label(10,0,"Ingresos", arial10BoldFormat);
        s1.addCell(l10);
        Label l11 = new Label(11,0,"Extracciones/adelantos", arial10BoldFormat);
        s1.addCell(l11);
        Label l12 = new Label(12,0,"Total Gasto", arial10BoldFormat);
        s1.addCell(l12);
        Label l13 = new Label(13,0,"Saldo final", arial10BoldFormat);
        s1.addCell(l13);
        Number n3;
        Number n4;
        Number n5;
        Number n6;
        Number n7;
        Number n8;
        Number n9;
        Number n10;
        Number n11;
        Number n12;
        Number n13;
        
        //Trae la info indicada
        /* Iniciales, Fecha, Cantidad_DVD,  Cantidad_Pedidos, Total_Ventas, Total_Gasto, Saldo_Final,
           Total_Ingreso, Total_Extadel, Ventas_Pendiente,
           Ventas_S2, Ventas_S3,  Saldo_Inicial*/
         String consulta="SELECT * from Reportes_Caja "+where() +" order by Fecha";
       // System.out.println(consulta);
         ResultSet resultSet = traeInfo(consulta);
           //Carga todas las filas 
        int i=0;
        while (resultSet.next()){
            i=i+1;
            l1 = new Label(1,i,resultSet.getString("Iniciales"), wrappedText);
            s1.addCell(l1);
            l2 = new Label(2,i,resultSet.getString("Fecha"), wrappedText);
            s1.addCell(l2);
            n3 = new Number(3,i,resultSet.getDouble("Saldo_Inicial"), wrappedText);
            s1.addCell(n3);
            n4 = new Number(4,i,resultSet.getDouble("Cantidad_DVD"), wrappedText);
            s1.addCell(n4);
            n5 = new Number(5,i,resultSet.getDouble("Cantidad_Pedidos"), wrappedText);
            s1.addCell(n5);
            n6 = new Number(6,i,resultSet.getDouble("Total_Ventas"), wrappedText);
            s1.addCell(n6);
            n7 = new Number(7,i,resultSet.getDouble("Ventas_S2"), wrappedText);
            s1.addCell(n7);
            n8 = new Number(8,i,resultSet.getDouble("Ventas_S3"), wrappedText);
            s1.addCell(n8);
            n9 = new Number(9,i,resultSet.getDouble("Ventas_Pendiente"), wrappedText);
            s1.addCell(n9);
            n10 = new Number(10,i,resultSet.getDouble("Total_Ingreso"), wrappedText);
            s1.addCell(n10);
            n11 = new Number(11,i,resultSet.getDouble("Total_Extadel"), wrappedText);
            s1.addCell(n11);
            n12 = new Number(12,i,resultSet.getDouble("Total_Gasto"), wrappedText);
            s1.addCell(n12);
            n13 = new Number(13,i,resultSet.getDouble("Saldo_Final"), wrappedText);
            s1.addCell(n13);
        }
            l6 = new Label(12,i+1,"TOTAL:", arial10BoldFormat);
            s1.addCell(l6);
            Formula f7 = new Formula(13,i+1,"SUM(n2:n"+(i+1)+")",wrappedText);
            if (i>0) s1.addCell(f7);
         }catch(Exception e){e.printStackTrace();}
    }
    
    protected String where(){
        String val=" ";
        switch(opcion1){
             case 1: val=  " WHERE Iniciales like '"+param1+"' and Fecha ='"+param2+"' "; break;
             case 2: val=  " WHERE Fecha between '"+param1+"' and '"+param2+"' "; break;
             case 3: val=  " WHERE Fecha between '"+param1+"' and '"+param2+"' "; break;
         }
        return val;
    }

    
}
